package com.example.Sao.Adapter;

import android.animation.ValueAnimator;
import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.Sao.MyActivity.ReviseActivity;
import com.example.Sao.MyBean.Lbean;
import com.example.Sao.R;

import java.util.List;

import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;

/**
 * @ProjectName: scan
 * @Package: com.example.Sao.Adapter
 * @ClassName: ProgressAdpter
 * @Description: 进度条加载适配器
 * @Author: 阿毛
 * @CreateDate: 2020/5/11 15:05
 * @UpdateUser: 更新者：
 * @UpdateDate: 2020/5/11 15:05
 * @UpdateRemark: 更新说明：
 * @Version: 1.0
 */
public class ProgressAdpter extends RecyclerView.Adapter<ProgressAdpter.mViewHolder>{
    private Context mContext;
    private List<Lbean>lbeanList;
    public ProgressAdpter(Context mContext,List<Lbean>lbeanList){
        this.mContext = mContext;
        this.lbeanList = lbeanList;
    }
    @Override
    public int getItemCount() {
        return 3;
    }

    @NonNull
    @Override
    public ProgressAdpter.mViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.adpter_progress,viewGroup,false);
        return new ProgressAdpter.mViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ProgressAdpter.mViewHolder mViewHolder, int i) {
        Lbean lbean = lbeanList.get(i);
        mViewHolder.name.setText(lbean.getMess());
        setAnimation(mViewHolder.progressBar,lbean.getProgress());

    }
    class mViewHolder extends RecyclerView.ViewHolder{
        private TextView name;
        private ProgressBar progressBar;
        public mViewHolder(View v){
            super(v);
            name = v.findViewById(R.id.name);
            progressBar = v.findViewById(R.id.progress);
        }
    }
    private void setAnimation(final ProgressBar view, final float mProgressBar) {
        ValueAnimator animator = ValueAnimator.ofInt(0, (int)mProgressBar).setDuration(3000);
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                view.setProgress((int) valueAnimator.getAnimatedValue());
            }
        });
        animator.start();
    }
}
